{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "<h1> HLA Typing </h1>\n",
    "\n",
    "This short tutorial illustrates the use of Fred2 to predict the HLA type from NGS data.\n",
    "\n",
    "**Note1**:\n",
    "The HLA Typing tools have to be globally executable!\n",
    "\n",
    "**Note2**:\n",
    "Fred2 only provides shallow wrapper classes. That means Fred2 directly forwards the input to the command line tools without any sanity checking and also only returns the most probable HLA genotype without any additional information, as the algorithms are very different."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2> Chapter 1: The basics </h2>\n",
    "<br/>\n",
    "We first start with importing the needed packages."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "from Fred2.HLAtyping import HLATypingFactory"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we can initialize for example `OptiType` by using the `HLATypingFactory` and predict the HLA type for a given NGS file. In this case the input is a RNA-Seq paired-end file in fastq format. But the input type can vary from prediction method to prediction method. Please familiarize yourself with the tool's options you are using."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<p><code>\n",
    ">python OptiTypePipeline.py --help  \n",
    "usage: OptiType [-h] --input INPUT [INPUT ...] (--rna | --dna) [--beta BETA]  \n",
    "                [--enumerate ENUMERATE] --outdir OUTDIR [--verbose]\n",
    "\n",
    "OptiType: 4-digit HLA typer\n",
    "\n",
    "optional arguments:\n",
    "  -h, --help            show this help message and exit\n",
    "  --input INPUT [INPUT ...], -i INPUT [INPUT ...]\n",
    "                        Fastq files with fished HLA reads. Max two files (for\n",
    "                        paired-end)\n",
    "  --rna, -r             Specifiying the mapped data as RNA.\n",
    "  --dna, -d             Specifiying the mapped data as DNA.\n",
    "  --beta BETA, -b BETA  The beta value for for homozygosity detection.\n",
    "  --enumerate ENUMERATE, -e ENUMERATE\n",
    "                        The number of enumerations.\n",
    "  --outdir OUTDIR, -o   OUTDIR\n",
    "                        Specifies the out directory to which all files should\n",
    "                        be written\n",
    "  --verbose, -v         Set verbose mode on.\n",
    "</code></p>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[HLA-A*31:01, HLA-A*68:01, HLA-B*40:01, HLA-B*51:01, HLA-C*15:02, HLA-C*03:04]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "opti = HLATypingFactory(\"OptiType\")\n",
    "opti.predict(\"./Data/CRC_81_N_1_fished.fastq\", \"/tmp/\", options=\"./Data/CRC_81_N_2_fished.fastq -r\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
